


from selenium.webdriver import ActionChains
from selenium.webdriver.common.by import By


class BasePage:

    def __init__(self,driver):

        self.driver =driver


    #寻找元素
    def locater_element(self,loc):
        # print("1>>>",loc)
        return self.driver.find_element(*loc)

    # 设置值的关键字
    def send_keys(self,loc,val):
        self.locater_element(loc).send_keys(val)

    #单击的关键字
    def click(self,loc):
        # print("2>>>",loc)
        self.locater_element(loc).click()
    #双击
    def double_click(self,loc):
        ActionChains(self.driver).double_click(self.locater_element(loc)).perform()

    #获取打开的所有窗口
    def get_allwindows(self):

        return self.driver.window_handles

    #获取当前driver 所在的窗口
    def get_current_window(self):
        return self.driver.current_window_handle


    def goto_otherwindow(self,windowhandle):
        self.driver.switch_to.window(windowhandle)

    def getattributevalue(self,loc,attribute):
        return self.locater_element(loc).get_attribute(attribute)

    def goto_iframe(self,frameloc):
        frameelement=self.locater_element(frameloc)
        return self.driver.switch_to.frame(frameelement)
        # pass
    #释放所有iframe,需要重新选择iframe进入
    def goto_default_content(self):
        self.driver.switch_to.default_content()

    def goto_alert(self):
        self.driver.switch_to.alert()